import { format, isToday, isYesterday } from 'date-fns'

export const getTime = (time, index = 1) => {
  if (index == 1) {
    console.log(time, 'time');
    return format(new Date(time), "yyyy-MM-dd");
  }else if (index == 2) {
    let timeArr = (time / 1000 / 60).toFixed(2).split(".");
    let min = parseInt(timeArr[0]);
    let seconds = (timeArr[1] / 100 * 60).toFixed(0)
    // console.log(`${min}:${seconds}`);
    if (seconds < 10) {
      seconds = '0' + seconds
    }
    return `${min}:${seconds}`;
  } else if(index == 3) {
    if (isToday(time)) {
      return format(new Date(time), "HH:mm");
    }else if(isYesterday(time)){
      return `昨天${format(new Date(time), "HH:mm")}`
    }else{
      return format(new Date(time), "yyyy-MM-dd");
    }
  }
}